home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
threads
/
ThreadsTestUtils.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-11-30
|
5KB
|
175 lines
/* begincopyright
Copyright (c) 1988 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94304
endcopyright */
/*
* ThreadsTestUtils.c
*
* Demers, November 30, 1989 5:38:41 pm PST
*
* Basic regression tests for threads
*/
#include "xr/BasicTypes.h"
#include "xr/Threads.h"
#include "xr/ThreadsBackdoor.h"
#include "xr/ThreadsPrivate.h"
#include "xr/ThreadsStatsPrivate.h"
#include "xr/ThreadsMsgPrivate.h"
#include "xr/UIO.h"
#include "xr/ThreadsSignalsPrivate.h"
#include "xr/Errno.h"
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/time.h>
#include <netinet/in.h>
void (*XR_testFailedProc)() = NIL;
void
XR_TestFailed(msg)
char *msg;
{
if( msg == NIL ) msg = "(no message)";
XR_ConsoleMsg("\n\nTEST FAILED: %s\n\n", msg);
if( XR_testFailedProc != NIL ) {
(*XR_testFailedProc)(msg);
} else {
XR_CallDebugger();
}
for(;;) XR_SpinStep(100000);
/*NOTREACHED*/
}
void
PutInterval(from, to)
struct timeval *from;
struct timeval *to;
{
int sec, msec, usec;
sec = to->tv_sec - from->tv_sec;
usec = to->tv_usec - from->tv_usec;
if( usec < 0 ) {
usec += 1000000;
sec -= 1;
}
msec = ((usec+500)/1000);
XR_ConsoleMsg("%d.%03d", sec, msec);
}
void
DoATest(testName, testProc)
char *testName;
void (*testProc)();
{
static struct itimerval itvOn = { {0, 0}, {36000, 0} };
static struct itimerval itvOff = { {0, 0}, {0, 0} };
struct timeval realStart, realEnd;
struct itimerval itvDone;
# if XR_STATS
int nsw, nswi;
# endif
XR_ConsoleMsg("\nStarting test of %s ...\n\n", testName);
(void)gettimeofday(&realStart, 0);
if( XR_sysArea->sa_numVP == 1 ) {
(void)setitimer(ITIMER_PROF, /*val=*/ &itvOn, /*oval=*/ 0);
}
# if XR_STATS
nsw = XR_sysArea->sa_stats[XR_STATS_Switch];
nswi = XR_sysArea->sa_stats[XR_STATS_SwitchIdle];
(*testProc)();
nsw = XR_sysArea->sa_stats[XR_STATS_Switch] - nsw;
nswi = XR_sysArea->sa_stats[XR_STATS_SwitchIdle] - nswi;
# else
(*testProc)();
# endif
(void)gettimeofday(&realEnd, 0);
if( XR_sysArea->sa_numVP == 1 ) {
(void)setitimer(ITIMER_PROF, /*val=*/ &itvOff, /*oval=*/ &itvDone);
}
XR_ConsoleMsg("\n... done test of %s.\nTimes: real ", testName);
PutInterval(&realStart, &realEnd);
if( XR_sysArea->sa_numVP == 1 ) {
XR_ConsoleMsg(", cpu ");
PutInterval(&itvDone.it_value, &itvOn.it_value);
}
# if XR_STATS
XR_ConsoleMsg(".\nThread switches: %d, idle: %d", nsw, nswi);
# endif
XR_ConsoleMsg(".\n\n");
}
/*
* Utility random number generator for tests ...
* ... stolen from Unix library rand.c
*/
static struct XR_MLRep randLock;
static unsigned long rand_Y[] = {
0x8ca0df45, 0x37334f23, 0x4a5901d2, 0xaeede075, 0xd84bd3cf,
0xa1ce3350, 0x35074a8f, 0xfd4e6da0, 0xe2c22e6f, 0x045de97e,
0x0e6d45b9, 0x201624a2, 0x01e10dca, 0x2810aef2, 0xea0be721,
0x3a3781e4, 0xa3602009, 0xd2ffcf69, 0xff7102e9, 0x36fab972,
0x5c3650ff, 0x8cd44c9c, 0x25a4a676, 0xbd6385ce, 0xcd55c306,
0xec8a31f5, 0xa87b24ce, 0x1e025786, 0x53d713c9, 0xb29d308f,
0x0dc6cf3f, 0xf11139c9, 0x3afb3780, 0x0ed6b24c, 0xef04c8fe,
0xab53d825, 0x3ca69893, 0x35460fb1, 0x058ead73, 0x0b567c59,
0xfdddca3f, 0x6317e77d, 0xaa5febe5, 0x655f73e2, 0xd42455bb,
0xe845a8bb, 0x351e4a67, 0xa36a9dfb, 0x3e0ac91d, 0xbaa0de01,
0xec60dc66, 0xdb29309e, 0xcfa52971, 0x1f3eddaf, 0xe14aae61,
};
static long rand_j=23, rand_k=54;
unsigned
RandomInRange(range)
unsigned range;
{
unsigned long m;
XR_MonitorEntry(&randLock);
m = rand_Y[rand_j]+rand_Y[rand_k];
rand_Y[rand_k] = m;
rand_j = rand_j - 1;
rand_k = rand_k - 1;
if(rand_j<0) rand_j = 54;
if(rand_k<0) rand_k = 54;
XR_MonitorExit(&randLock);
return ((m >> 5) & 0x7ffffff) % range;
}
bool
CoinToss()
{
return (RandomInRange(2) < 1);
}
bool
CoinToss2(i, n)
unsigned i, n;
{
return (RandomInRange(n) < i);
}